package com.king.event;

import java.io.PrintWriter;
import java.io.StringWriter;

import lombok.Getter;
import lombok.Setter;

/**
 * 异常-事件，此事件在MainWin中监听
 * 
 * @author king
 * @date 2025年6月27日-16:08:21
 */
@Getter
@Setter
public class ExceptionEvent {

	private String msg;

	private int status;

	private Throwable ex;

	public static ExceptionEvent build(int status, String msg) {
		ExceptionEvent e = new ExceptionEvent();
		e.setStatus(status);
		e.setMsg(msg);
		return e;
	}

	public static ExceptionEvent build(String msg) {
		return build(500, msg);
	}

	public static ExceptionEvent build(Throwable ex) {
		ex.printStackTrace();
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		ex.printStackTrace(pw);
		pw.flush();
		return build(sw.toString());
	}

}
